package com.example.administrator.yuejian2.model;

import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.TrainBean;
import com.example.administrator.yuejian2.service.TrainDetailService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.administrator.yuejian2.other.Url.BASEURL;
import static com.example.administrator.yuejian2.other.Url.URL1;

public class TrainDetailModel {
    private Retrofit retrofit;
    private TrainDetailService trainDetailService;

    public TrainDetailModel()
    {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL+URL1)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        trainDetailService=retrofit.create(TrainDetailService.class);
    }

    public void getTrainDetail(String train_id, final RetrofitListener listener)
    {
        Call<TrainBean> call=trainDetailService.getTrainDetail(train_id);
        call.enqueue(new Callback<TrainBean>() {
            @Override
            public void onResponse(Call<TrainBean> call, Response<TrainBean> response) {
                listener.onSuccess(response.body(),1);
            }

            @Override
            public void onFailure(Call<TrainBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
}
